/*=====================================================================================

 payments.do: 
	
   Creates the dividend from the file APF_Data.xlsx
   
   NOTE: Stata's "import excel" is not suported on the BLS's platform, hence
         this file cannot be executed at the BLS!
		   
	
		Lorenz Kueng, Feb 2015
		
=======================================================================================*/

cap n log close PFD_01
log using "$homedir/log-files/PFD_01_$date.log", replace name(PFD_01)					


*================================================================================
* Dividend Payments
*================================================================================

import excel "$homedir/data/APF_Data.xlsx", sheet("4. narrative analysis") cellrange(B3:I232) firstrow clear

	generate date = mdy(month,day,year)
	format date %td
	order  date

	rename  bymail        by_mail
	rename  directdeposit direct_deposit
	rename  Aannouncement announcement 


	* keep only payments

	drop if date==d(07aug2008) // drop announcement date of $1,200 energy rebate 

	keep date announcement by_mail direct_deposit year month

	generate dateM = ym(year,month)
	format dateM %tm
	order  dateM

	keep if by_mail!=. | direct_deposit!=. | announcement!=.

	// fill in dividend amount when paid out, either by check or direct deposit
	replace announcement = announcement[_n+1] if announcement==. 
	replace announcement = announcement[_n+1] if announcement==.

	// keep payment days, ie drop announcement dates
	drop if by_mail==. & direct_deposit==.
	
	generate APFD = announcement if by_mail==1        & dateM<=m(1992m12) // before 1993, all dividends were mailed
	replace  APFD = announcement if direct_deposit==1 & dateM>=m(1993m1)  // starting in 1993, fraction of dividends is via direct deposits

	collapse (max) APFD, by(dateM)
	
	drop if APFD == .
	label var APFD "APFD"

	tsset dateM
	compress
	label data "Alaska Permanent Fund Dividend"

	save "$homedir/data/stata/payments.dta", replace

log close PFD_01

